package com.baitiaojun.tenant.mapper;

import com.baitiaojun.common.enums.impl.TenantStatusEnums;
import com.baitiaojun.common.utils.date.DateTimeUtils;
import com.baitiaojun.common.utils.string.StringUtils;
import com.baitiaojun.mybatisplus.core.basemapper.MyBaseMapper;
import com.baitiaojun.tenant.pojo.MasterTenantDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface MasterTenantMapper extends MyBaseMapper<MasterTenantDO> {

    default MasterTenantDO selectMasterTenant(String tenant) {
        LambdaQueryWrapper<MasterTenantDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(tenant), MasterTenantDO::getTenant, tenant)
                .eq(MasterTenantDO::getStatus, TenantStatusEnums.NORMAL.getCode())
                .gt(MasterTenantDO::getExpirationDate, DateTimeUtils.parseDate(DateTimeUtils.getDateTime()));
        return selectOne(queryWrapper);
    }
}
